<script setup lang="ts">
import type {
  CalculationStatusMonitoringSelectCalculationStatusPageResult1 as A,
  CalculationStatusMonitoringPublicParams,
  CustomDialogInstance,
} from '@/types'
import { calculationStatusMonitoringApi } from '@/api'
// ------------------use------------------
// #region
const props = defineProps<{
  info: A['baseDataValInternalList'][number] | null
  dateType: string
}>()
const { withLoading, vLoading } = useDefineLoading({
  destroyNode: true,
})
const [logStr, setLogStr] = useState('')
// #endregion
// ------------------静态变量------------------
// #region

// #endregion
// ------------------动态变量------------------
// #region

// #endregion
// ------------------ref-----------
// #region
const dialogRef = ref<CustomDialogInstance | null>(null)
// #endregion
// ------------------reactive------
// #region
// #endregion
// ------------------computed------
// #region

// #endregion
// ------------------生命周期------------------
// #region

// #endregion
// ------------------内置方法---------------------
// #region
// #endregion
// ------------------方法---------------------
// #region
async function open() {
  dialogRef.value?.open?.()
  await nextTick()
  dialogRef.value?.setSaving?.(false)
  getLogStr()
}
function close() {
  dialogRef.value?.close?.()
}
async function getLogStr() {
  const { dataTime, indicatorNumber } = unref(props.info)!
  const params: Omit<
    CalculationStatusMonitoringPublicParams,
    'indicatorName'
  > = {
    dataTime,
    indicatorNumber: indicatorNumber as string,
    key: props.dateType,
  }
  const { data: res } = await withLoading(
    calculationStatusMonitoringApi.selectExecutionProcess,
  )(params)
  setLogStr(res ?? '')
}
// #endregion
defineExpose({
  open,
  close,
})
</script>

<template>
  <CustomDialog
    ref="dialogRef"
    title="执行日志"
    width="600px"
    fullable
    :show-confirm-button="false"
    cancel-button-text="关闭"
  >
    <BScrollbar
      v-loading
      class="padding-sm !min-height-vh-1/3 box-border"
    >
      {{ logStr }}
      <el-empty v-show="!logStr" description="暂无日志!" />
    </BScrollbar>
  </CustomDialog>
</template>

<style lang="scss" scoped>
//------------------组件样式------------------
.b-scrollbar {
  white-space: break-spaces;
  text-indent: 2em;
  background: var(--el-fill-color-light);
  color: var(--el-text-color-primary);
  line-height: 1.5;
}
//-------------样式穿透-------------
</style>
